<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>文件系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui/css/layui.css">
    <link rel="stylesheet" href="../css/scroll-bar.css">
    <link rel="stylesheet" href="../css/sub-page.css">
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../lib/nprogress/nprogress.css">
</head>

<body>
    <div class="ok-body">
        <!--面包屑导航区域-->
        <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>数据集管理</cite></a>
                <a><cite>文件系统</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
                <i class="layui-icon layui-icon-refresh"></i>
            </a>
        </div>
        <!--工具栏-->
        <!--  <okToolbar>
            <button class="layui-btn" id="refresh">
                <i class="layui-icon layui-icon-refresh"></i>刷新目录树
            </button>
            <span>共有数据：<i id="countNum"></i> 条</span>
        </okToolbar> -->

        <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
        <ul id="demo"></ul>
    </div>
    <!--js逻辑-->
    <script src="../lib/layui/layui.js"></script>
    <script src="../lib/nprogress/nprogress.js"></script>
    <script>
        NProgress.start();
        window.onload = function () {
            NProgress.done();
        }
    layui.config({
        base: '../lib/layui/lay/modules/'
    }).extend({
        treetable: 'treetable/treetable'
    }).use(['element', 'table', 'form', 'jquery','treetable','tree'], function () {
        var element = layui.element;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var treetable = layui.treetable;
    
        // 渲染表格
        treetable.render({
            treeColIndex: 2,          // treetable新增参数
            treeSpid: -1,             // treetable新增参数
            treeIdName: 'resourceid',       // treetable新增参数
            treePidName: 'pid',     // treetable新增参数
            treeDefaultClose: true,   // 默认是全部展开的，如果需要默认全部关闭，加上treeDefaultClose:true即可。
            treeLinkage: false,        // 父级展开时是否自动展开所有子级
            elem: '#tableId',
            url: '/dataset/folderlist',
            cols: [[
                {type: 'numbers'},
                /* {field: 'resourceid', title: 'ID'}, */
                {field: 'resourcename', title: '文件夹'},
                {field: 'path', title: '路径'},
                /* {field: 'pid', title: 'pid'},  */
                 {templet: '#statusTpl', width: 120, align: 'center', title: '状态'}, 
                 {fixed: 'right',templet: '#operationTpl', width: 120, align: 'center', title: '操作'}
                
            ]]
        });
        treetable.foldAll('#tableId');

        $('#refresh').click(function(){
            $.ajax({
                    url: '/dataset/refreshdirectory',
                    method: 'post',
                    success: function (res) {
                        if (res.code == 1) {
                            layer.msg('操作成功');
                        } else {
                            layer.msg('操作失败');
                        }
                    },
                    error: function (data) {}
                })
				
        });

            table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'import') {
                //layer.msg(JSON.stringify(data));
                layer.open({
                    title: '数据导入',
                    type: 2,
                    shade: false,
                    maxmin: true,
                    shade: 0.5,
                    area: ['90%', '90%'],
                    content: '/fdm/import',
                    zIndex: layer.zIndex,
                    end: function () {
                        $(".layui-laypage-btn")[0].click();
                    },
                    success:function(layero, index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        body.find('#id').val(data.resourceid);
                        body.find('#md5path').val(data.md5path);
                        body.find('#path').val(data.path);
                        console.log(body.find('#id').val());
                    }
                });           
            }
        });       
    })
</script>
    <!--模板-->
    <script type="text/html" id="operationTpl">
        <a href="javascript:;" title="导入数据" lay-event="import" class="layui-btn layui-btn-xs layui-bg-blue" id="btnimport">导入数据</a>
</script>
    <!--模板-->
    <script type="text/html" id="statusTpl">
        <a href="javascript:;" title="状态" class="layui-btn layui-btn-xs  {{ d.flag== 0? 'layui-bg-orange' : 'layui-bg-green'}} ">
                {{ d.flag== 0? '未完成' : '已入库'}}
            </a>
       
    </script>
</body>

</html>